package com.zking.web;

import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zking.dao.domain.SysUser;
import com.zking.service.UserService;
import com.zking.utils.RedisUtil;
import com.zking.utils.RequestUtils;


@Controller
@RequestMapping(value = "/music", name = "音乐控制器")
public class MusicInfoController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisUtil redisUtil;
    
    @RequestMapping(value = "/login", name = "音乐登陆")
    @RequiresPermissions({"/usersPage"})
    @ResponseBody
    public String login(){
        SysUser user = RequestUtils.currentLoginUser();
        Set<String> authorization = userService.findPermissionsByUserId(user.getId());
        return "该用户有如下权限" + authorization;
    }
    
    //简单的测试
    @RequestMapping(value = "/redisUtil", name = "Redis的使用")
    @ResponseBody
    public String redisUtilTest() throws InterruptedException{
    	redisUtil.set("aaaKey", "aaaValue");
        redisUtil.expire("aaaKey", 10);
        Object aaaKey1 = redisUtil.get("aaaKey");
        TimeUnit.SECONDS.sleep(11);
        Object aaaKey2 = redisUtil.get("aaaKey");
        return "aaaKey1"+aaaKey1+",aaaKey2="+aaaKey2;
    }

}
